package com.buaa.airticketbookingsystem.Controller;

import com.buaa.airticketbookingsystem.Entity.Flight;
import com.buaa.airticketbookingsystem.Entity.Ticket;
import com.buaa.airticketbookingsystem.Service.FlightService;
import com.buaa.airticketbookingsystem.Service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin
@RestController
public class GetFlightDetailController {

    @Autowired
    private FlightService flightService;

    @Autowired
    private TicketService ticketService;

    @PostMapping("/getFlightDetail")
    public Map<String, Object> GetFlightDetail(@RequestBody Map<String, String> remap){
        String f_id = remap.get("f_id");
        Flight f = flightService.selectFlightByID(f_id);
        List<ArrayList<String>> resList = new ArrayList<>();
        Map<String, Object> resMap = new HashMap<>();
        for(int i = 1; i <= f.getTicket_number(); i++){
            ArrayList<String> temp = new ArrayList<>();
            for(char j = 'A'; j <= 'F'; j++){
                String t_id = f_id + String.valueOf(i) + String.valueOf(j);
                Ticket t = ticketService.getTicketById(t_id);
                if(t.getBePurchased() == 0){
                    temp.add("a");
                } else{
                    temp.add("d");
                }
            }
            resList.add(temp);
        }
        resMap.put("res", true);
        resMap.put("message", "成功返回");
        resMap.put("list", resList);
        return resMap;
    }
}
